<?php
/*
 * Camelot PHP Tools
 *
 * @version 2.0
 * @author Bendsoft
 * @package PHP Tools
 * @subpackage Camelot
 * @license FreeBSD License (www.bendsoft.com/licensing/)
 * 
 */

//namespace Camelot\PHPTools\Procedures;

/**
 * Handle Stored Procedures
 * @author Bendsoft
 */
class SharePointProcedure extends CamelotExceptionHandling {
    
    /**
     * The returned camelot xml object 
     * @var CamelotXmlReader
     */
    public $CamelotSoap;
    
    /**
     * Execute a stored procedure
     * @param object $command
     */
    public function __construct($command) {

        $validateResult = $command->isValid();
        if ($validateResult !== true) {
            $this->exception = $validateResult;
            $this->commandStatus = false;
            
            // Throw CamelotException
            if(!SILENT_EXCEPTIONS) {
                throw $validateResult;      
            }
            
            // Stop.
            return;
        }
        
        $commandResult = $command->execute();
        if(is_object($commandResult) && isset($commandResult->commandStatus) && $commandResult->commandStatus === false) {
            // Transfer the exception status from the result object
            $this->exception = $commandResult->exception;
            $this->commandStatus = false;
            
            // Throw CamelotException
            if(!SILENT_EXCEPTIONS) {
                throw $commandResult->exception;        
            }
        } elseif ($commandResult instanceof CamelotException) {
            $this->exception = $commandResult;
            $this->commandStatus = false;
            
            // Throw CamelotException
            if(!SILENT_EXCEPTIONS) {
                throw $commandResult;      
            }
        } else {
            $this->exception = null;
            $this->commandStatus = true;
            $this->CamelotSoap = isset($commandResult->CamelotSoap) ? $commandResult->CamelotSoap : null;
        }
    }
}

?>
